#!/bin/bash
APP_DIR="$(cd "$(dirname "$0")/../Resources" && pwd)"
cd "$APP_DIR"

# Free port 3880 if held
lsof -ti :3880 | xargs kill -9 2>/dev/null

# Open default browser to UI
(sleep 1.2 && open "http://localhost:3880") &

# Run standalone engine
if [ -x "/usr/local/bin/node" ]; then
    /usr/local/bin/node server.js
elif [ -x "/opt/homebrew/bin/node" ]; then
    /opt/homebrew/bin/node server.js
else
    node server.js
fi
